import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/assets/scss/index.scss'
import '@/js/rem.js'
import lazyPlugin from 'vue3-lazy'
import loadingDirective from '@/components/base/loading/directive'
import noResultDirective from '@/components/base/no-result/directive'

import storage from 'good-storage'
import { FAVORITE_KEY, PLAY_KEY } from '@/js/constant'
import { processSongs } from '@/service/song'

const favoriteSongs = storage.get(FAVORITE_KEY, [])
if (favoriteSongs.length > 0) {
  processSongs(favoriteSongs).then((songs) => {
    store.commit('setFavoriteLst', songs)
    storage.set(FAVORITE_KEY, songs)
  })
}

const historySongs = storage.get(PLAY_KEY, [])
if (historySongs.length > 0) {
  processSongs(historySongs).then((songs) => {
    store.commit('setPlayHistory', songs)
    storage.set(PLAY_KEY, songs)
  })
}

createApp(App).use(store).use(router).use(lazyPlugin, {
  loading: require('@/assets/images/default.png')
}).directive('loading', loadingDirective).directive('no-result', noResultDirective).mount('#app')
